<?php

namespace Api\Member\AuthManager\Self;

use Api\RepositoryResourceTrait;

class LogRepository
{
    use RepositoryResourceTrait;

    /**
     * 构造方法
     */
    public function __construct(
        \Api\Member\AuthManager\Auth       $Auth,
        \Api\Member\AuthManager\Models\Log $Model
    ) {
        $this->Auth   = $Auth;
        $this->Models = compact('Model');
    }

    /**
     * 记录日志
     *
     * @return void
     */
    public function make($description)
    {
        $backtrace = debug_backtrace(2, 1);
        
        $log = $this->Model;
        $log->member_manager_id = $this->Auth->id;
        $log->type_str          = $backtrace[0]['class'].'@'.$backtrace[0]['function'];
        $log->description       = $description;
        $log->request_ip        = app('request')->ip();
        $log->saveOrFail();
    }

}
